<template>
    <div id="ClassManage">
       <el-row style="margin-bottom:20px">
           <el-col :span="1">
               <el-button type="primary" @click="pushToaddNewClass">新增班级</el-button>
           </el-col>
       </el-row>
       <table class="table table-bordered">
           <tbody>
               <tr class="tableHeader">
                   <td>城市</td>
                   <td>校区</td>
                   <td>班级名</td>
                   <td>辅导时间</td>
                   <td>预科时间</td>
                   <td>开班时间</td>
                   <td>计划人数</td>
                   <td>实际人数</td>
                   <td>班主任</td>
                   <td>任课老师</td>
                   <td>课程</td>
                   <td>操作</td>
               </tr>
               <tr v-for="(item,key) in dataSource" :key="key" class="tableRow">
                   <td>
                       {{item.city.cityName}}
                   </td>
                   <td>
                       {{item.campus.campusName}}
                   </td>
                   <td>
                       {{item.className}}
                   </td>
                   <td>{{item.assistTime|formateDate}}</td>
                   <td>{{item.prepareTime |formateDate }}</td>
                   <td>{{item.openTime | formateDate}}</td>
                   <td>{{item.planCount}}</td>
                   <td>{{item.realCount}}</td>
                   <td>{{item.headTeacher}}</td>
                   <td>{{item.courseTeacher}}</td>
                   <td>{{item.subject}}</td>
                   <td>
                       <el-button type="success" plain size="mini" @click="handleEdit(item)">编辑</el-button>
                   </td>
               </tr>
           </tbody>
       </table>
    </div>
</template>
<script>
export default {
    data(){
        return {
            dataSource: [],
            baseURL: window.baseURL + "/backstage/classManage/findByPage?token="+this.$token
        }
    },
    methods: {
        pushToaddNewClass(){
            this.$router.push({name:'AddNewClass'})
        },
        handleEdit(item){
            this.$router.push({name: 'EditClass',params:{classInfo: item}})
        }
    },
    filters: {
        formateDate(value){
            var date = new Date(value);
            var year = date.getFullYear();
            var month = date.getMonth()+1;
            var day = date.getDate();
            return year+"-"+month+"-"+day
        }
    },
    created(){
        this.loadDataWithURL(this.baseURL);
    },
    beforeRouteUpdate (to, from, next) {
        if(to.name === "班级管理"){
            this.loadDataWithURL(this.baseURL);
        }
        next();
    }
}
</script>
<style lang="scss" scoped>
    #ClassManage {
        width: 100%;
        height: 100%;
        padding: 40px;
        position: absolute;
    }
</style>
